package service;

import java.sql.SQLException;
import java.util.ArrayList;



import dao.postScriptDAO;
import dto.AddressDTO;
import dto.FileListDTO;
import dto.ListDTO;
import dto.MemberDTO;
import dto.PagingDTO;
import dto.PrivacyDTO;
import dto.PropertyDTO;
import dto.RefundDTO;
import dto.RoomDTO;
import dto.postScriptDTO;





import util.Utilities;


public class postScriptService {
	private postScriptDAO dao;
	public postScriptService(postScriptDAO dao){
		this.dao=dao;
	}
	public void insertContent(postScriptDTO pdto)throws Exception {
		int no = dao.updateNo();
		String writeDate = Utilities.getNow();
		String c = Utilities.changeContentForDB(pdto.getPostScript_content());
		
		pdto.setPostScript_no(no);
		pdto.setPostScript_writedate(writeDate);
		pdto.setPostScript_content(c);	
		//pdto.setPostScript_score(0);
		//pdto.setPostScript_memberid("test");
		//pdto.setPostScript_resno(no);
		//pdto.setPostScript_roomno(21);
		System.out.println(pdto);
		dao.insertContent(pdto);
		
		pdto.setPostScript_writedate(Utilities.changeDayFormat(writeDate));
		
	}
	public ArrayList<postScriptDTO> getAllMemberList() {
		ArrayList<postScriptDTO> list =  dao.getAllMemberList();
		return list;
		
	}
	public void delete(int no)throws Exception {
		dao.delete(no);
	}
	public postScriptDTO getContentByNoForForm(int no) {
		return dao.selectContentByNO(no);
	}
	public void modifyContent(postScriptDTO pdto) {
		pdto.setPostScript_content(Utilities.changeContentForDB(pdto.getPostScript_content()));
		//pdto.setPostScript_writedate(Utilities.getNow());
		pdto.setPostScript_writedate(Utilities.changeDayFormat2(Utilities.getNow()));
		//2. 수정 처리		
		System.out.println("서비스단계 : "+pdto);
		dao.updateContent(pdto);
		//3. writedate 포멧 변경
		//pdto.setPostScript_writedate(Utilities.changeDayFormat(pdto.getPostScript_writedate()));
	}
	public void registerMember(MemberDTO mdto) throws SQLException{
		dao.insertContent(mdto);
	}
	public ArrayList<postScriptDTO> getMemberList(String postScript_memberid) {
		ArrayList<postScriptDTO> list =  dao.getMemberList(postScript_memberid);
		return list;
	}
	
	public postScriptDTO searchPicture(postScriptDTO pdto)throws SQLException{
	
		pdto.setPostScript_roomno(pdto.getPostScript_roomno());
		return dao.selectPictureMemberById(pdto.getPostScript_memberid());
	}
	public String searchPicture2(String postScript_memberid)throws SQLException{
		return dao.selectPictureMemberById2(postScript_memberid);
	}
	public ArrayList<postScriptDTO> getContentByRoom(int roomno) {
		ArrayList<postScriptDTO> list =  dao.getContentByRoom(roomno);
		return list;
	}
	public RoomDTO roombyvalue(int roomno)throws SQLException {
		return dao.roombyvalue(roomno);		
	}
	public ArrayList<postScriptDTO> postbyvalue(int roomNo) {
		ArrayList<postScriptDTO> list =  dao.postbyvalue(roomNo);	
		return list;
	}
	public MemberDTO memberbyvalue(String memberId) {
		return dao.memberbyvalue(memberId);
	}
	public ListDTO getBoardListByPage(int page,int postScript_roomno)throws SQLException {
		ArrayList<postScriptDTO> list =  dao.selectBoardListByPage(page,postScript_roomno);
		for(postScriptDTO pdto : list ){
			pdto.setPostScript_writedate(Utilities.changeDayFormat(pdto.getPostScript_writedate()));
		}
		
		int totalcontent = dao.selectTotalContent(postScript_roomno);
		PagingDTO pagingDTO = new PagingDTO(totalcontent,page);
		System.out.println(pagingDTO);
		ListDTO ldto = new ListDTO(list,pagingDTO);
		System.out.println(ldto);
		return ldto;
	}
	public String filebyvalue(int roomno) {
		return dao.filebyvalue(roomno);
	}
	public String privacybyvalue(int roomno) {
		return dao.privacybyvalue(roomno);
	}
	public String propertybyvalue(int roomno) {
		return dao.propertybyvalue(roomno);
	}
	public String refundbyvalue(int roomno) {
		return dao.refundbyvalue(roomno);
	}
	public AddressDTO addressbyvalue(int roomno) {
		AddressDTO adto =  dao.addressbyvalue(roomno);	
		return adto;
	}
	public ArrayList<FileListDTO> searchFileListByRoomNo(int roomno) {
		return dao.selectFileListByRoomNo(roomno);
	}
	public String selectRoomnoByFileName(String filename) {
		return dao.selectRoomnoByFileName(filename);
	}
}
	